<template>
	<div>
		<div class="box">
			<div class="title">
				<span class="tag"></span>
				更换车辆
			</div>
			<AForm
				ref="form1"
				v-model="formData.previousData"
				:config="formList1"
				:layout="{ column: true }"
				:state="state"></AForm>
			<AForm
				ref="form2"
				v-model="formData.subsequentData"
				:config="formList2"
				:layout="{ column: true }"
				:state="state"></AForm>
		</div>
	</div>
</template>

<script>
	import AForm from '@/components/A/A-form/form/index.vue';
	export default {
		name: '',
		components: { AForm },
		props: {
			value: {
				type: Object,
				default: () => {
					return {};
				},
			},
			state: {
				required: false,
			},
		},
		dicts: [],
		data() {
			return {};
		},
		dicts: ['quota_operation_type'],
		inject: ['dictList_provide'],
		computed: {
			dictList_dict() {
				return this.dictList_provide();
			},
			formData: {
				get() {
					return this.useVModel.call(this);
				},
				set(val) {
					this.$emit('input', val);
				},
			},
			formList1() {
				return [
					{
						label: '原品牌/车系/车型',
						state: 'readonly',
						format: ({ val, item, row }) => {
							return `${row.carBrandName} ${row.carSeriesName} ${row.carModelName}`;
						},
					},
					{
						label: '原车架号',
						prop: 'carVinNo',
						state: 'readonly',
					},
					{
						label: '原车牌号',
						prop: 'carPlateNo',
						state: 'readonly',
					},
					{
						label: '原车辆指导价/元',
						prop: 'carGuidePrice',
						state: 'readonly',
						type: 'price',
					},
					// {
					// 	label: '原车辆使用性质',
					// 	prop: 'operationType',
					// 	state: 'readonly',
					// 	type: 'select',
					// 	dict: {
					// 		list: this.dict.type.quota_operation_type,
					// 	},
					// },
					// {
					// 	label: '原车辆所属公司',
					// 	prop: 'carAffiliationKey',
					// 	state: 'readonly',
					// 	type: 'select',
					// 	dict: {
					// 		list: this.dictList_dict.company,
					// 		label: 'deptName',
					// 		value: 'deptId',
					// 	},
					// },
					// {
					// 	label: '原车辆运营城市',
					// 	prop: 'carOperateCityVal',
					// 	state: 'readonly',
					// },
					// {
					// 	label: '原车辆当期评估价',
					// 	prop: 'carCurrentAppraisal',
					// 	state: 'readonly',
					// 	type: 'price',
					// },
				];
			},
			formList2() {
				return [
					{
						label: '更换原品牌/车系/车型',
						type: 'select_dialog',
						propLabel: 'carModelName',
						prop: 'carId',
						selectDialogOptions: {
							type: 'car',
							params: {
								businessType: 7, // 闲置中
								carLockType: 2, // 未锁定
							},
							success: ({ data, row }) => {
								this.serCarData({ data, row });
							},
						},
						rules: true,
					},
					{
						label: '更换车架号',
						prop: 'carVinNo',
						rules: true,
					},
					{
						label: '更换车牌号',
						prop: 'carPlateNo',
						rules: true,
					},
					{
						label: '更换车辆指导价/元',
						prop: 'carGuidePrice',
						type: 'price',
						rules: true,
						state: 'readonly',
					},
					// {
					// 	label: '更换车辆使用性质',
					// 	prop: 'operationType',
					// 	type: 'select',
					// 	dict: {
					// 		list: this.dict.type.quota_operation_type,
					// 	},
					// 	rules: true,
					// 	state: 'readonly',
					// },
					// {
					// 	label: '更换车辆所属公司',
					// 	prop: 'carAffiliationKey',
					// 	type: 'select',
					// 	dict: {
					// 		list: this.dictList_dict.company,
					// 		label: 'deptName',
					// 		value: 'deptId',
					// 	},
					// 	rules: true,
					// 	state: 'readonly',
					// },
					// {
					// 	label: '更换车辆运营城市',
					// 	prop: 'carOperateCityVal',
					// 	rules: true,
					// 	type: 'input',
					// 	state: 'readonly',
					// },
					// {
					// 	label: '更换车辆当期评估价',
					// 	prop: 'carCurrentAppraisal',
					// 	type: 'price',
					// 	rules: true,
					// 	state: 'readonly',
					// },
				];
			},
		},
		created() {},
		mounted() {},
		methods: {
			setDefaultData(row) {
				for (const key in this.formList2) {
					if (Object.hasOwnProperty.call(this.formList2, key)) {
						this.formData.subsequentData[key] =
							this.formData.previousData[key];
					}
				}
				row.carId = this.formData.previousData.carId; //车辆id
				row.carSeating = this.formData.previousData.carSeating; // 座位数
				row.carPlateNo = this.formData.previousData.carPlateNo; //车牌号
				row.carVinNo = this.formData.previousData.carVinNo; // 车架号
				row.carBrandId = this.formData.previousData.carBrandId; //品牌id
				row.carBrandName = this.formData.previousData.carBrandName; //品牌
				row.carSeriesName = this.formData.previousData.carSeriesName; //车系
				row.carSeriesId = this.formData.previousData.carSeriesId; //车系id
				row.carModelId = this.formData.previousData.carModelId; //车型id
				row.carModelName = this.formData.previousData.carModelName; //车型
				row.carGuidePrice = this.formData.previousData.carGuidePrice; //更换车辆指导价

				row.carAffiliationKey =
					this.formData.previousData.carAffiliationKey; //车辆所属公司
				row.carAffiliationVal =
					this.formData.previousData.carAffiliationVal; //车辆所属公司
				row.carSeating = this.formData.previousData.carSeating; // 座位数
				row.carCc = this.formData.previousData.carCc; // 排量
				row.carTypeStr = this.formData.previousData.carTypeStr; // 车辆种类
				row.carPowerTypeStr =
					this.formData.previousData.carPowerTypeStr; // 车辆类型
				row.carManufacturer =
					this.formData.previousData.carManufacturer; // 厂商
				row.isGreen = this.formData.previousData.isGreen;
				row.carMileage = this.formData.previousData.carMileage; // 公里
				row.carLicenseCityKey =
					this.formData.previousData.carLicenseCityKey; //上牌城市
				row.carLicenseCityVal =
					this.formData.previousData.carLicenseCityVal; //上牌城市
				row.carAffiliationKey =
					this.formData.previousData.carAffiliationKey; //开发城市
				row.carAffiliationVal =
					this.formData.previousData?.carAffiliationVal; //开发城市

				this.$emit(
					'getDecorationList',
					this.formData.previousData.carSeating,
				);
			},
			serCarData({ row, data }) {
				if (this.formData.previousData.carVinNo === data.vinNo) {
					this.$message({
						message: '新旧车辆不能相同!',
						type: 'warning',
					});
					return;
				}
				row.carId = data.carId; //车辆id
				row.carSeating = data.seatNum; // 座位数
				row.carPlateNo = data.carNo; //车牌号
				row.carVinNo = data.vinNo; // 车架号
				row.carBrandId = data.brandId; //品牌id
				row.carBrandName = data.brandName; //品牌
				row.carSeriesName = data.seriesName; //车系
				row.carSeriesId = data.seriesId; //车系id
				row.carModelId = data.modelId; //车型id
				row.carModelName = data.modelName; //车型
				row.carGuidePrice = this.toNumberRide(data.price, 10000); //更换车辆指导价

				let item = this.dictList_dict.company.find(
					e => e.deptId == data.propertyRightId,
				);
				row.carAffiliationKey = data.propertyRightId; //车辆所属公司
				row.carAffiliationVal = item.deptName; //车辆所属公司
				row.carSeating = data.seatNum; // 座位数
				row.carCc = data.liter; // 排量
				row.carTypeStr = data.vehicleCategory; // 车辆种类
				row.carPowerTypeStr = data.isGreen == 1 ? '新能源车' : '燃油车'; // 车辆类型
				row.carManufacturer = data.makerName; // 厂商
				row.isGreen = data.isGreen;
				row.carMileage = data.mileage; // 公里
				row.carLicenseCityKey = data.propertyRightId; //上牌城市
				row.carLicenseCityVal = item.deptName; //上牌城市
				row.carAffiliationKey = data.propertyRightId; //开发城市
				row.carAffiliationVal = item?.deptName; //开发城市

				this.$emit('getDecorationList', data.seatNum);
			},
		},
		beforeDestroy() {
			this.setDefaultData(this.formData.previousData);
		},
	};
</script>

<style lang="scss" scoped>
	.box {
		border-radius: 8px;
		background-color: #fff;
		.title {
			font-size: 14px;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 22px;
			padding-top: 15px;
			padding-bottom: 15px;
			// border-bottom: 1px solid #e9e9e9;
			display: flex;
			align-items: center;
			.tag {
				width: 8px;
				height: 8px;
				background-color: #1890ff;
				border-radius: 100%;
				margin-right: 10px;
			}
			.price {
				font-size: 14px;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #1890ff;
				line-height: 20px;
				margin-left: 20px;
			}
		}
	}
</style>
